package cn.bbstone.pisces2.client;

import cn.bbstone.pisces2.client.executor.ClientExecutor;
import cn.bbstone.pisces2.client.executor.ClientExecutorPool;
import cn.bbstone.pisces2.comm.Const;
import cn.bbstone.pisces2.config.Config;
import cn.bbstone.pisces2.config.ConfigFactory;
import cn.bbstone.pisces2.config.ConfigModel;
import cn.bbstone.pisces2.util.CtxUtil;

/**
 * FileTask default SBUF_SIZE min 4M, if there are 10 client, min require memory 4M x 10 = 40M
 * SBUF_SIZE set 32M, min require memory 32M x 10 = 320M
 *
 */
public class ClientStarter {

    public static void main(String[] args) {
        long maxMem = Runtime.getRuntime().maxMemory()/(1024*1024);
        if (maxMem < 64) { // 64MB
            throw new RuntimeException("run one client require memory minimal 64 MB.");
        }
        // init configs
        ConfigModel configModel = ConfigFactory.loadConfigs(Const.CLIENT);
        CtxUtil.setConfigModel(configModel);

        for (int i = 0; i < CtxUtil.getConfigModel().getConnNum(); i++) {
            ClientExecutor clientExecutor = new ClientExecutor();
            ClientExecutorPool.submit(clientExecutor);
        }

//        FileClient client = new FileClient();
//        client.startup();
    }
}
